<?PHP
session_start();
include("../config/connect.php");
include("../public/common.php");

if( !isset($_SESSION["gs_user"]) ) 
{
	$url = "Location:login.php";
	header($url);
}

$nPage = SetUrlParamInt("page");
if( $nPage < 0 )
	$nPage = 0;
	
$showtype = CheckUrlParamNoDie("showtype");
if( $showtype == "a" )
{
	$sql = "select * from other_trade where 1 order by id desc";
}
else
{
	$sql = "select * from other_trade where state=0 order by id desc";
}
	
	
$result = mysql_query( $sql );
$row_num = mysql_num_rows( $result );

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>购物兔</title>
<style type="text/css">
<!--
body,td,th {
	font-family: 宋体;
	font-size: 13px;
	color: #000;
}
body {
	background-color: #FFF;
}
-->
</style>
<script language="javascript">

function ShowAll(  )
{
	window.location.href= "view_other_trade.php?showtype=a";
	//window.location.reload();
}

function ShowDefault(  )
{
	window.location.href= "view_other_trade.php?showtype=p";
	//window.location.reload();
}

function OnPageChange( type )
{
	if( type == "pre" )
	{
		window.location.href= "view_other_trade.php?showtype=<?PHP echo $showtype; ?>&page=<?PHP echo $nPage - 1; ?>";
	}
	else if( type == "next" )
	{
		window.location.href= "view_other_trade.php?showtype=<?PHP echo $showtype; ?>&page=<?PHP echo $nPage + 1; ?>";
	}
	else if( type == "first" )
	{
		window.location.href= "view_other_trade.php?showtype=<?PHP echo $showtype; ?>&page=0";
	}
	else if( type == "last" )
	{
		window.location.href= "view_other_trade.php?showtype=<?PHP echo $showtype; ?>&page=<?PHP echo floor($row_num/20); ?>";
	}
}

//var timeoutID = setTimeout("Update( )", 60000);
</script>
</head>

<body>
<a href="add_trade.php?opt=add">添加记录</a>
<table cellpadding="0" cellspacing="0" border="1" align="center">
	<tr>
    	<td height="25" width="50" align="center">序列号</td>
        <td width="143" align="center">时间</td>
      	<td width="175" align="center">产品Id</td>
        <td width="68" 	align="center">返现(元)</td>
        <td width="56" align="center">返现(%)</td>
        <td width="186" align="center">支付宝帐号</td>
        <td width="67" align="center">ip</td>
        <td width="307" align="center">标题</td>
        <td width="54" align="center">操作</td>
    </tr>
<?php
$id = SetUrlParamInt("id");
$limit = " limit ". $nPage*20 .",20";
if( $id != 0 )
{
	$sql = "update other_trade set state=1 where id=$id limit 1";
	mysql_query( $sql );
}

if( $showtype == "a" )
{
	$sql = "select * from other_trade where 1 order by id desc".$limit;
}
else
{
	$sql = "select * from other_trade where state=0 order by id desc".$limit;
}
	
$result = mysql_query( $sql );
while( $result && $row = mysql_fetch_assoc( $result ))
{
?>
<tr title="<?PHP echo $row["title"]; ?>">
    <td height="25" width="50" align="center"><?PHP echo $row["id"]; ?></td>
    <td width="143" align="center" title=""><?PHP echo $row["time"]; ?></td>
	<td width="175" align="center"><a href="add_trade.php?id=<?PHP echo $row["id"]; ?>&item_id=<?PHP echo $row["item_id"]; ?>"><?PHP echo $row["item_id"]; ?></a>&nbsp;</td>
	<td width="68" 	align="center"><?PHP echo $row["price"]; ?>&nbsp;</td>
	<td width="56" align="center"><?PHP echo $row["percent"]; ?>&nbsp;</td>
	<td width="186" align="center"><?PHP echo $row["tb_id"]; ?>&nbsp;</td>
    <td width="67" align="center"><?PHP echo $row["ip"]; ?>&nbsp;</td>
    <td width="307" align="center"><?PHP echo $row["title"]; ?>&nbsp;</td>
	<td width="54" align="center"><a href="view_other_trade.php?showtype=<?PHP echo $showtype; ?>&page=<?PHP echo $nPage; ?>&id=<?PHP echo $row["id"]; ?>">隐藏</a></td>
</tr>
<?PHP
}
?>
</table>

<table cellpadding="0" cellspacing="0" border="0" align="center">
	<tr>
   	  <td width="800" height="30" align="center">
   	    <input type="button" value="显示所有" onclick="javascript:ShowAll()" />&nbsp;
    	  <input type="button" value="默认" onclick="javascript:ShowDefault()" />&nbsp;&nbsp; <a href="#" onclick="javascript:OnPageChange('first');">首页</a>&nbsp;&nbsp;<a href="#" onclick="javascript:OnPageChange('next');">下页</a>&nbsp;&nbsp;<a href="#" onclick="javascript:OnPageChange('pre');">上页</a>&nbsp;&nbsp;<a href="#" onclick="javascript:OnPageChange('last');">末页</a></td>
    </tr>
</table>
</body>
</html>
